C#

推荐列表 站点导航

当前位置:首页 > 脚本编程 > C# >

C#_C#保存listbox中数据到文本文件的方法,本文实例讲述了C#保存listbox中

来源:网络整理  作者:fen  发布时间:2020-12-26 09:27
C#保存listbox中数据到文本文件的方法,本文实例讲述了C#保存listbox中数据到文本文件的方法。分享给大家供大家参考。...

private void SaveLstToTxt(ListBox lst) { sfd.Filter = "(*.txt)|*.txt"; if (sfd.ShowDialog() == DialogResult.OK) { string sPath = sfd.FileName; FileStream fs = new FileStream(sPath, FileMode.Create); StreamWriter sw = new StreamWriter(fs, Encoding.UTF8); int iCount = lst.Items.Count - 1; for (int i = 0; i <= iCount; i++) { sw.WriteLine(lst.Items[i].ToString()); } sw.Flush(); sw.Close(); fs.Close(); } }

相关热词:

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://v30.fanwenzhu.com/jiaob/c/9238.shtml

最新文章
热门文章
Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

C#_C#保存listbox中数据到文本文件的方法,本文实例讲述了C#保存listbox中

2020-12-26 编辑:fen

private void SaveLstToTxt(ListBox lst) { sfd.Filter = "(*.txt)|*.txt"; if (sfd.ShowDialog() == DialogResult.OK) { string sPath = sfd.FileName; FileStream fs = new FileStream(sPath, FileMode.Create); StreamWriter sw = new StreamWriter(fs, Encoding.UTF8); int iCount = lst.Items.Count - 1; for (int i = 0; i <= iCount; i++) { sw.WriteLine(lst.Items[i].ToString()); } sw.Flush(); sw.Close(); fs.Close(); } }

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://v30.fanwenzhu.com/jiaob/c/9238.shtml

相关文章

风云图片

推荐阅读

返回C#频道首页